!function (m) {
    var h = m.document, n = {};
    var l = n.util = {
        parseOptions: function (a) {
        }, sessionStorage: function () {
        }(), serialize: function (a) {
        }, deserialize: function (a) {
        }
    };

    function k(a) {
    }

    $.fn.emulateTransitionEnd = function (a) {
    };
    if (typeof define === "function") {
        define(n)
    } else {
        m.YDUI = n
    }

    function j(a, b) {
        this.$element = $(a);
        this.options = $.extend({}, j.DEFAULTS, b || {});
        this.init()
    }

    j.DEFAULTS = {
        speed: 300,
        autoplay: 5000,
        lazyLoad: false,
        pagination: ".slider-pagination",
        wrapperClass: "slider-wrapper",
        slideClass: "slider-item",
        bulletClass: "slider-pagination-item",
        bulletActiveClass: "slider-pagination-item-active"
    };

    function j(a, b) {
        this.$element = $(a);
        this.options = $.extend({}, j.DEFAULTS, b || {});
        this.init()
    }

    j.DEFAULTS = {
        speed: 300,
        autoplay: 3000,
        lazyLoad: false,
        pagination: ".slider-pagination",
        wrapperClass: "slider-wrapper",
        slideClass: "slider-item",
        bulletClass: "slider-pagination-item",
        bulletActiveClass: "slider-pagination-item-active"
    };
    j.prototype.init = function () {
        var b = this, c = b.options, a = b.$element;
        b.index = 1;
        b.autoPlayTimer = null;
        b.$pagination = a.find(c.pagination);
        b.$wrapper = a.find("." + c.wrapperClass);
        b.itemNums = b.$wrapper.find("." + c.slideClass).length;
        c.lazyLoad && b.loadImage(0);
        b.createBullet();
        b.cloneItem().bindEvent()
    };
    j.prototype.bindEvent = function () {
        var a = this, b = a.touchEvents();
        a.$wrapper.find("." + a.options.slideClass).on(b.start, function (c) {
            a.onTouchStart(c)
        }).on(b.move, function (c) {
            a.onTouchMove(c)
        }).on(b.end, function (c) {
            a.onTouchEnd(c)
        });
        $(m).on("resize.ydui.slider", function () {
            a.setSlidesSize()
        });
        ~~a.options.autoplay > 0 && a.autoPlay();
        a.$wrapper.on("click.ydui.slider", function (c) {
            if (!a.touches.allowClick) {
                c.preventDefault()
            }
        })
    };
    j.prototype.cloneItem = function () {
        var e = this, d = e.$wrapper, c = e.$wrapper.find("." + e.options.slideClass),
            a = c.filter(":first-child").clone(), b = c.filter(":last-child").clone();
        d.prepend(b);
        d.append(a);
        e.setSlidesSize();
        return e
    };
    j.prototype.createBullet = function () {
        var a = this;
        if (!a.$pagination[0]) {
            return
        }
        var b = '<span class="' + (a.options.bulletClass + " " + a.options.bulletActiveClass) + '"></span>';
        a.$pagination.append(b + new Array(a.itemNums).join('<span class="' + a.options.bulletClass + '"></span>'))
    };
    j.prototype.activeBullet = function () {
        var a = this;
        if (!a.$pagination[0]) {
            return
        }
        var d = a.itemNums, c = a.index % d >= d ? 0 : a.index % d - 1, b = a.options.bulletActiveClass;
        !!a.$pagination[0] && a.$pagination.find("." + a.options.bulletClass).removeClass(b).eq(c).addClass(b)
    };
    j.prototype.setSlidesSize = function () {
        var a = this, b = a.$wrapper.width();
        a.$wrapper.css("transform", "translate3d(-" + b + "px,0,0)");
        a.$wrapper.find("." + a.options.slideClass).css({width: b})
    };
    j.prototype.autoPlay = function () {
        var a = this;
        a.autoPlayTimer = setInterval(function () {
            if (a.index > a.itemNums) {
                a.index = 1;
                a.setTranslate(0, -a.$wrapper.width())
            }
            a.setTranslate(a.options.speed, -(++a.index * a.$wrapper.width()))
        }, a.options.autoplay)
    };
    j.prototype.stopAutoplay = function () {
        var a = this;
        clearInterval(a.autoPlayTimer);
        return a
    };
    j.prototype.setTranslate = function (b, c) {
        var a = this;
        a.options.lazyLoad && a.loadImage(a.index);
        a.activeBullet();
        a.$wrapper.css({transitionDuration: b + "ms", transform: "translate3d(" + c + "px,0,0)"})
    };
    j.prototype.touches = {
        moveTag: 0,
        startClientX: 0,
        moveOffset: 0,
        touchStartTime: 0,
        isTouchEvent: false,
        allowClick: false
    };
    j.prototype.onTouchStart = function (b) {
        if (b.originalEvent.touches) {
            b = b.originalEvent.touches[0]
        }
        var a = this, d = a.touches;
        d.allowClick = true;
        d.isTouchEvent = b.type === "touchstart";
        if (!d.isTouchEvent && "which" in b && b.which === 3) {
            return
        }
        if (d.moveTag == 0) {
            d.moveTag = 1;
            d.startClientX = b.clientX;
            d.touchStartTime = Date.now();
            var c = a.itemNums;
            if (a.index == 0) {
                a.index = c;
                a.setTranslate(0, -c * a.$wrapper.width());
                return
            }
            if (a.index > c) {
                a.index = 1;
                a.setTranslate(0, -a.$wrapper.width())
            }
        }
    };
    j.prototype.onTouchMove = function (c) {
        c.preventDefault();
        if (c.originalEvent.touches) {
            c = c.originalEvent.touches[0]
        }
        var a = this, d = a.touches;
        d.allowClick = false;
        if (d.isTouchEvent && c.type === "mousemove") {
            return
        }
        var b = d.moveOffset = c.clientX - d.startClientX;
        if (b != 0 && d.moveTag != 0) {
            if (d.moveTag == 1) {
                a.stopAutoplay();
                d.moveTag = 2
            }
            if (d.moveTag == 2) {
                a.setTranslate(0, -a.index * a.$wrapper.width() + b)
            }
        }
    };
    j.prototype.onTouchEnd = function () {
        var a = this, d = a.options.speed, b = a.$wrapper.width(), f = a.touches, c = f.moveOffset;
        setTimeout(function () {
            f.allowClick = true
        }, 0);
        if (f.moveTag == 1) {
            f.moveTag = 0
        }
        if (f.moveTag == 2) {
            f.moveTag = 0;
            var e = Date.now() - f.touchStartTime;
            if (e > 300 && Math.abs(c) <= a.$wrapper.width() * 0.5) {
                a.setTranslate(d, -a.index * a.$wrapper.width())
            } else {
                a.setTranslate(d, -((c > 0 ? --a.index : ++a.index) * b))
            }
            a.autoPlay()
        }
    };
    j.prototype.touchEvents = function () {
        var a = (m.Modernizr && !!m.Modernizr.touch) || (function () {
            return !!(("ontouchstart" in m) || m.DocumentTouch && document instanceof DocumentTouch)
        })();
        return {
            start: a ? "touchstart.ydui.slider" : "mousedown.ydui.slider",
            move: a ? "touchmove.ydui.slider" : "mousemove.ydui.slider",
            end: a ? "touchend.ydui.slider" : "mouseup.ydui.slider"
        }
    };

    function i(a) {
        return this.each(function () {
            var b = $(this), c = b.data("ydui.slider");
            if (!c) {
                b.data("ydui.slider", new j(this, a))
            }
        })
    }

    $(m).on("load.ydui.slider", function () {
        $("[data-ydui-slider]").each(function () {
            var a = $(this);
            a.slider(m.YDUI.util.parseOptions(a.data("ydui-slider")))
        })
    });
    $.fn.slider = i
}(window);